package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.GoodsDto;
import com.qs.pojo.entity.CollectGoods;
import com.qs.response.Response;
import com.qs.service.ICollectGoodsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 收藏的商品表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-10
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/collect/goods")
@RequiredArgsConstructor
public class CollectGoodsController {

    private final ICollectGoodsService collectGoodsService;

    /**
     * 保存用户收藏的商品
     * @param collectGoods
     * @return
     */
    @PostMapping("/save")
    public Response saveCollectGoods(@RequestBody CollectGoods collectGoods) {
        log.info("保存用户收藏的商品的请求进来了----------");
        collectGoodsService.saveCollectGoods(collectGoods);
        return Response.success();
    }

    /**
     * 查询用户收藏的商品
     * @param userId
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}/{userId}")
    public Response getCollectGoodsList(@PathVariable("pageNo") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @PathVariable("userId") Integer userId) {
        log.info("查询用户收藏的商品的请求进来了----------");
        Map<String,Object> map = collectGoodsService.getCollectGoodsList(pageNo,pageSize,userId);
        return Response.success(map);
    }

    /**
     * 查询周边商品
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/perimeter/list/{pageNo}/{pageSize}")
    public Response getPerimeterGoods(@PathVariable("pageNo") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize) {
        log.info("查询周边商品请求进来了----------");
        Map<String,Object> map = collectGoodsService.findPerimeterGoods(pageNo,pageSize);
        return Response.success(map);
    }


    /**
     * 取消收藏商品
     * @param id
     * @return
     */
    @DeleteMapping("/cancel/goods/{id}")
    public Response cancelCollectGoods(@PathVariable("id") Integer id) {
        log.info("取消收藏商品的请求进来了----------");
        collectGoodsService.removeById(id);
        return Response.success();
    }
}
